﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TYBase;

namespace TYRTUBase {
    public static class ScanerParaHelper {
        private static ScanerPara scanerPara_JNS;
        private static ScanerPara scanerPara_Other;

        static ScanerParaHelper() {
            scanerPara_JNS = new ScanerPara {
                baudRate = 115200,
                dataBits = 8,
                parity = Parity.Even,
                stopBits = StopBits.One,
                NewLine = new byte[] { 0x0D }
            };

            scanerPara_JNS.CMD_OPEN = ("LON\r").AsBytes();
            scanerPara_JNS.CMD_Close = ("LONF\r").AsBytes();


            scanerPara_Other = new ScanerPara { baudRate = 9600, dataBits = 8, parity = Parity.None, stopBits = StopBits.One, NewLine = new byte[] { 0x0D } };


            scanerPara_Other.CMD_OPEN = new byte[] { 0x16, 0x54, 0x0D };
            scanerPara_Other.CMD_Close = new byte[] { 0x16, 0x55, 0x0D };
        }

        public static ScanerPara GetScanerPara(EnumScanerType enumScanerType) {
            switch (enumScanerType) {
                case EnumScanerType.基恩士:
                    return scanerPara_JNS;

                case EnumScanerType.其他:
                    return scanerPara_Other;

                default:
                    break;
            }
            return null;
        }
    }

    public class ScanerPara : ComPara {
        public ScanerPara() {
        }
        public ScanerPara(ScanerPara para) {
            baudRate = para.baudRate;
            dataBits = para.dataBits;
            NewLine = para.NewLine;
            parity = para.parity;
            stopBits = para.stopBits;
        }
        public byte[] CMD_OPEN;

        public byte[] CMD_Close;
    }

    public class ComPara {

        public int Com;

        public int baudRate;

        public Parity parity;

        public int dataBits;

        public StopBits stopBits;

        public byte[] NewLine = new byte[] { 0x0D, 0x0A };

        public string IP { get; set; }

        public int Port { get; set; }

    }
}